﻿using AutoMapper;
using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using NuGet.Protocol.Core.Types;
using ProductionManage.Models.DataModel;
using System.Collections.Generic;
using System.Threading.Tasks;
using test.demo.Model.PRO生产管理;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using wangyaxin.Jiangzhenying;
using wangyaxin.Jiangzhenying.UnitInfos;
using wangyaxin.Jiangzhenying.UnitInfos.Dto;
using wangyaxin.Jiangzhenying.Workstations.Dto;
using wangyaxin.Wang.Dto;

namespace wangyaxin.Web.Jiangzhenying
{
    public class JzyViewsController : Controller
    {
        private readonly IRepository<UnitInfo, int> _UnitInfoRepository;
        private readonly UnitInfoServise _service;
        private readonly WorkstationService _workservice;
        private readonly IMapper _mapper; // 依赖注入 IMapper

        public JzyViewsController(IRepository<UnitInfo, int> UnitInfoRepository, IMapper mapper,UnitInfoServise service, WorkstationService workservice)
        {
            _UnitInfoRepository = UnitInfoRepository;
             _service= service;
            _workservice = workservice;
            _mapper = mapper;
        }

        #region ///计量单位
        /// <summary>
        /// 单位信息列表视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowUnitInfoLists()
        {
            return View();
        }

        /// <summary>
        /// 添加单位信息视图
        /// </summary>
        /// <returns></returns>
        public IActionResult AddUnitInfo()
        {
            return View();
        }

        /// <summary>
        /// 修改单位信息视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateUnitInfo()
        {
            return View();
        }

        /// <summary>
        /// 获取单位信息列表
        /// </summary>
        /// <returns></returns>
        public IActionResult GetUnidInfoLists(string? unitCode, string? unitName)
        {
            var list = _service.GetUnidInfoList(unitCode, unitName);
            return Json(list);
        }

        /// <summary>
        /// 添加单位信息
        /// </summary>
        /// <returns></returns>
        public IActionResult AddUnitInfoas(UnitInfo unitInfo)
        {
            var result = _service.AddUnitInfo(unitInfo);
            return Json(result);
        }

        /// <summary>
        /// 更新单位信息
        /// </summary>
        /// <param name="unitInfo"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult UpdateUnitInfos(UpdateUnitInfoDto unitInfo)
        {
            var updUnitInfo = _service.UpdateUnitInfo(unitInfo);
            return Json(updUnitInfo);
        }

        /// <summary>
        /// 删除单位信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DeleteUnitInfos(int id)
        {
            var delUnitInfo = _service.DeleteUnitInfo(id);
            return Json(delUnitInfo);
        }
        #endregion

        #region ///工作站
        /// <summary>
        /// 工作站信息视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowWorkstationList()
        {
            return View();
        }

        /// <summary>
        /// 添加工作站信息视图
        /// </summary>
        /// <returns></returns>
        public IActionResult AddWorkstation()
        {
            return View();
        }

        /// <summary>
        /// 获取工位列表
        /// </summary>
        /// <returns></returns>
        public IActionResult GetWorkstationList(string? workstationCode, string? workstationName, int workShopId, int processId)
        {
            var list = _workservice.GetWorkstationLists(workstationCode, workstationName, workShopId, processId);
            return Json(list);
        }

        /// <summary>
        /// 新增工作站
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult AddWorkstations(Workstation input)
        {
            var workstation = _workservice.AddWorkstation(input);
            return Json(workstation);
        }

        /// <summary>
        /// 删除工作站
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DeleteWorkstations(int id)
        {
            var workstation = _workservice.DeleteWorkstation(id);   
            return Json(workstation);
        }

        /// <summary>
        /// 绑定动态车间
        /// </summary>
        /// <returns></returns>
        public IActionResult GetWorkShopList()
        {
            var workShop = _workservice.GetWorkShop();
            return Json(workShop);
        }

        /// <summary>
        /// 绑定动态工序
        /// </summary>
        /// <returns></returns>
        public IActionResult GetProProcessList()
        {
            var proProcess = _workservice.GetProProcess();
            return Json(proProcess);
        }

        #endregion
    }
}
